package com.cj.image.controller;

import com.cj.image.bean.ImageTableBean;
import com.cj.image.mapper.ImageMapper;
import com.cj.image.mapper.TagMapper;
import com.cj.image.service.ImageService;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("image")
public class ImageController {

    @Autowired
    private ImageMapper imageMapper;
    @Autowired
    private ImageService imageService;

    @GetMapping("/getImageTable/{tag_id}")
    public List<ImageTableBean> getImageTable(@PathVariable String tag_id) {
        return imageMapper.getImageTables(tag_id);
    }

    @GetMapping("/getImageTablesLoop/{tag_id}")
    public List<ImageTableBean> getImageTablesLoop(@PathVariable String tag_id) {
        return imageMapper.getImageTablesLoop(tag_id);
    }

    @GetMapping("/getImage")
    public void getImage(@RequestParam String image_id, HttpServletResponse response) {
        imageService.getImageIo(image_id,response);
    }

    @GetMapping("/getAllFileMonth")
    public List<String> getImageTable() {
        return imageMapper.getAllFileMonth();
    }

    @GetMapping("/getImageTableByFileMonth/{fileMonth}")
    public PageInfo<ImageTableBean> getImageTableByFileMonth(@PathVariable String fileMonth, int pageNum, int pageSize) {
        return imageService.getImageTableByFileMonthWithPagination(fileMonth,pageNum,pageSize);
    }

}
